<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Auction
 * @version 	: 1.1
 * COPYRIGHT    : 2010
 * ------------------------------------------------------
 *
 * Created on	:  Sep 13, 2010
 *
 */
session_start();
// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RClassesImporter::cls('controllers.AbstractFrontController');
RCoreImporter::cls( "mvc.AbstractController" );
RClassesImporter::cls('dbo.dtos.RegisterDTO');
/**
 * The controller for State application
 *
 */
class RegisterFrontController extends AbstractFrontController {
	
	var $_model;
	
	function __construct() {
		parent::__construct();
		SysApplication::importModelCls('RegisterModel');
		$this->_model = new RegisterModel();
		$this->registerTask ( "new", "edit" );
		$this->registerTask ( "apply", "save" );
	}	
	function display() {
		if (SysRequest::getVar('msg')){
			echo "<div class=\"message\"> ".SysRequest::getVar('msg')." </div>";
		}		
		$this->_model = new RegisterModel();
		$model = $this->_model;
		$root_path = SYS_ROOT_URL;		
		$name = $_REQUEST['name'];
		$email = $_REQUEST['email'];
		$subject = $_REQUEST['subject'];
		$content = $_REQUEST['content'];		
		$RegisterDTO = new RegisterDTO();
		$RegisterDTO->bind($_POST);		  		
	 	//--------------------captcha------------------------------------------------
	 	RCoreImporter::cls("security.CaptchaImgProtect");
		$capcha = new CaptchaImgProtect($_POST['verify']);
		$imageUrl = $capcha->getImageUrl();
		$inputhtml = $capcha->createInputHtml("");
		$captchaImg = $capcha->createImageTag(7);
		$result = $capcha->isValid();
	//--------------------end of captcha------------------------------------------------
		if ($_POST['send'] && $result == FALSE){
			echo "<div class=\"message\"> ".SysLanguage::_('WRONG_SECURITY')." </div>";
		}
		if ( $_POST['send'] && $result == true){
//			$_SESSION['content'] = $_REQUEST['content'];
//			$a = $_SESSION['content'];
// 		RubikHelper::debugPrePrint($a);
			if (empty($name) || empty($email) || empty($content)){
				$name1 = $_REQUEST['name'];
				$email1 = $_REQUEST['email'];
				$subject1 = $_REQUEST['subject'];
				$content1 = $_REQUEST['content'];
				echo "<div class=\"message\"> ".SysLanguage::_('EMPTY')." </div>";				
				eval('echo "'.SysApplication::loadTemplate('front/default').'";');	
				return FALSE;
			}
			$result = $model->saveRegisterDTO($RegisterDTO);
			$RegisterDTO->resetToNull();
			if ($result){
				$msg = SysLanguage::_('SUCCESS');
				$this->setRedirectToCurrentFunction($msg);
//				$this->setRedirectToCurrentFunction();
//				echo "<div class=\"message\"> ".SysLanguage::_('SUCCESS')." </div>";				
			}			
		}
		eval('echo "'.SysApplication::loadTemplate('front/default').'";');	
	}
		
}